#pragma comment(lib, "ws2_32.lib")

#include <memory>
#include <winsock2.h>

#include "header.h"

Header::Header()
{
	memset(_name, 0x00, sizeof(_name));
	_bodyLength = 0;
}

Header::Header(const Header &rhs)
{
	memcpy(_name, rhs.getName(), 4);
	_bodyLength = rhs.getBodyLength();
}

const char* Header::getName() const { return _name; }
const unsigned int Header::getLength() const { return 16; }
const unsigned int Header::getBodyLength() const { return _bodyLength; }

void Header::setRawValue(void *rawValue)
{
	char *raw = (char *)rawValue;
	memcpy(_name, raw, 4);
	_bodyLength = ntohl(*((unsigned int *)(raw + 4)));
}

const char* Header::getRawValue()
{
	memset(_rawValue, 0x00, sizeof(_rawValue));
	memcpy(_rawValue, _name, 4);
	unsigned int bodyLength = htonl(_bodyLength);
	memcpy(_rawValue + 4, &bodyLength, sizeof(bodyLength));
	return _rawValue;
}

void Header::setName(const char *name)
{
	memcpy(_name, name, 4);
}

void Header::setBodyLength(const unsigned int length)
{
	_bodyLength = length;
}

